<%@ page language="java" import="java.util.*" import="java.sql.*" import = "orm.*"  pageEncoding="utf-8" errorPage="errorPage.jsp"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%  
  org.apache.struts.util.TokenProcessor.getInstance().saveToken(request);  
  %>
<% 	String courseOpt = ""; 
	String knowledgesOpt = "";
	List courses = (List)session.getAttribute("courseList");
	if (courses == null || courses.size() == 0){
		courseOpt = "<option value=''>您没有课程！</option>";
	}
	else {
		for(int i = 0; i < courses.size(); i++){
			Course course = (Course)courses.get(i);
			String name = course.getCoursename();
			if (i == 0){
				courseOpt += "<option value = '" + name + "' selected='selected' >" + name + "</option>";
				continue;
			}
			courseOpt += "<option value = '" + name + "'>" + name + "</option>";
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href = "<%=basePath %>"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加考试</title>
<link href="css/tStyles.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/date.js"></script>
<script>
var oCalendarChs=new PopupCalendar("oCalendarChs"); //初始化控件时,请给出实例名称:oCalendarChs
oCalendarChs.weekDaySting=new Array("日","一","二","三","四","五","六");
oCalendarChs.monthSting=new Array("一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月");
oCalendarChs.oBtnTodayTitle="今天";
oCalendarChs.oBtnCancelTitle="取消";
oCalendarChs.Init();
</script>
<script type="text/javascript">
	function commit(){
		if (check()){
			var opt = confirm("确认发布该考试？");
			if (opt == true){
				this.testForm.action = "manageTemplates.do?action=newTest";
				return this.testForm.submit;
			}
			return false;
		}
		return false;
	}
	
	function check(){
		if (document.getElementById("testName").value == ""){
			alert("请输入考试名称！");
			return false;
		}
		if (document.getElementById("startDate").value == ""){
			alert("请选择开始时间！");
			return false;
		}
		if (document.getElementById("endDate").value == ""){
			alert("请选择结束时间！");
			return false;
		}
		var d1 = new Date(document.getElementById("startDate").value.replace(/\-/g, '/'));
 		var d2 = new Date(document.getElementById("endDate").value.replace(/\-/g, '/'));
 		var today = new Date();
 		if (parseInt((today -d1)/1000/60/60/24) > 1){
 			alert("开始时间不应在今天之前！");
 			return false;
 		}
 		if (d2 < d1){
 			alert("结束时间不应在开始时间之前！");
 			return false;
 		}
 		if (document.getElementById("testTime").value == ""){
 			alert("请输入考试时间！");
 			return false;
 		}
 		return true;	
	}
</script>
<script type="text/javascript">
	function onlyNum(e){
		 var event = window.event || e;
    	 var key = document.all ? event.keyCode : event.which;
    	 return key >= 48 && key <= 57
	}
</script>
</head>
<% 	User tea  =(User) session.getAttribute("Teacher");  
	if (tea == null){
		response.sendRedirect(path + "/index.jsp");
	}
%> 

<body>
	<!-- CONTAINER START -->
<div id = "container">
<!-- HEADER START -->
        <div id = "top">
        	<div id = "navigation">
            	<html:link page="/teacher/teacher.jsp" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;首页</html:link>
                <html:link page="/teacher/notice.jsp" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;通知</html:link>
                <html:link action="manageQuestions.do?action=startManagement" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;题库</html:link>
                <html:link action="manageKnowledges.do?action=startManagement" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;知识点</html:link>
                <html:link action="manageTemplates.do?action=startManagement" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;试卷模板</html:link>
                <html:link action="gradeManagement.do?action=startMana" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;成绩管理</html:link>
                <html:link page="/teacher/studentMana.jsp" styleClass = "link">&nbsp;&nbsp;&nbsp;&nbsp;学生管理</html:link>
            </div>
        </div>
        <!-- HEADER END -->
        
	<!-- LOGIN START -->
        <div id = "login">
        	<div id = "name">
        	<%=tea.getRealname()%>
            </div>
        	<html:link page="/teacher/teacherInfo.jsp" styleClass="viewInfo">·查询个人信息</html:link>
          	<p><html:link page="/teacher/teaModifyPwd.jsp" styleClass="modifyPwd">·修改密码</html:link></p>
            <p><html:link page="/teacher/letter.jsp" styleClass="letter">·站内信</html:link></p>
            <p><html:link forward="logout" styleClass="logout">·注销登录</html:link></p>
  		</div>
        <!-- LOGIN END -->
        
        <!-- CLOCK START -->
  		<div id = "clock">
        	<iframe src="index/clock.html" height="407" width="296" frameborder="0" scrolling="no"
            		marginheight="0" marginwidth="0" id="clockFrame" name="clockFrame"></iframe>
		</div>
        <!-- CLOCK END -->
        
        <!-- MAIN START -->
      	<div id = "main">
        	<center>
        	<form name="testForm" method="post" action="" onsubmit="return commit();">
        	 <input   type="hidden"   name="org.apache.struts.taglib.html.TOKEN" 
        	value="<%=session.getAttribute("org.apache.struts.action.TOKEN")%>"   /> 
        	<div id = "subject">
            	<br /><br />
            	<span class="text" style="font-size:26px;"><strong>&nbsp;&nbsp;科目:</strong></span>
              		<select name="course" id="course" style="width:100px;" >
              			<%=courseOpt %>
             		</select>
            </div><% if (courses != null && courses.size() != 0){ %>
            <div id = "newTest">   	
       	  		<table border="1">
                	<tr>
    					<td width="332" height="28" colspan="2" align="center"><strong>发布新考试</strong></td>
  					</tr>
  					<tr>
    					<td>考试名称：</td>
    					<td><input type="text" name="testName" id="testName" maxlength="50"/></td>
  					</tr>
  					<tr>
  						<td>开始时间：</td>
  						<td><input type="text" name="startDate" id="startDate" onclick="getDateString(this,oCalendarChs)"
  						readonly="readonly" /></td>
  					</tr>
  					<tr>
  						<td>结束时间：</td>
  						<td><input type="text" name="endDate" id="endDate" onclick="getDateString(this,oCalendarChs)"
  						readonly="readonly" /></td>
  					</tr>
  					<tr>
  						<td>考试时间：</td>
  						<td><input type="text" name="testTime" id="testTime" 
  						onkeypress="return onlyNum(event);" maxlength="3"/>分钟</td>
  					</tr>
  					<tr>
    					<td align="center"><input type="submit" name="submit" value="发布考试"/></td>
    					<td align="center"><input type="button" name="cancel" value="取消" 
    					onclick="window.location.href='manageTemplates.do?action=startManagement'"/></td>                       	
                    </tr>
              </table>
            </div><%}else{ %><input type="button" name="cancel" value="返回" 
    					onclick="window.location.href='manageTemplates.do?action=startManagement'"/><%} %>
            </form>
            </center>
   	  	</div>
	<!-- MAIN END -->
        
	<!-- FOOTER START -->
	<div id = "footer">
  	</div>
	<!-- FOOTER END -->
        
</div>
    <!-- CONTAINER END -->
</body>
</html>